<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/29 0029
 * Time: 16:03
 */

namespace app\home\controller;
use think\Db;



class Works extends Base
{
        public function index(){
            session('cg_id',null);
            session('venue_id',null);
            session('style_id',null);

            $data_banner = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and type=5')->order('sort desc,id desc')->field('banner_img,out_link')->find();
            $this->assign('data_banner',$data_banner);
            //选择基地
            $data_jd = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->field('title,id')->select();
            $this->assign('data_jd',$data_jd);
            //选择场馆
            $data_venue = Db::name('venue')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->field('name,id')->select();
            $this->assign('data_venue',$data_venue);
            //选择风格
            $data_style = Db::name('style')->where('is_del=0 and is_show=1 and sign="pc"')->order('sort desc,id desc')->field('name,id')->select();
            $this->assign('data_style',$data_style);
            $str_ids = explode('-',input('param.id'));
            $where = 'is_del=0 and is_show=1 and sign="pc"';
            if(input('param.id')){
                if($str_ids[0] && intval($str_ids[0]) > 0){
                    $cg_id = intval($str_ids[0]);
                    if(session('cg_id') == $cg_id){
                        session('cg_id',null);
                    }else{
                        $where .= " and cg_id = ".$cg_id;
                        session('cg_id',$cg_id);
                    }
                }
                if($str_ids[1] && intval($str_ids[1]) > 0){
                    $venue_id = intval($str_ids[1]);
                    $where .= " and venue_id = ".$venue_id;
                    session('venue_id',$venue_id);
                }
                if($str_ids[2] && intval($str_ids[2]) > 0){
                    $style_id = intval($str_ids[2]);
                    $where .= " and style_id = ".$style_id;
                    session('style_id',$style_id);
                }
            }
            $this->assign('SESSION',isset($_SESSION)?$_SESSION:[]);
            //作品
            $data = Db::name('zp')->where($where)->order('sort desc,id desc')->field('title,id,main_img,ps_time')->limit(8)->select();
            $data_next= Db::name('zp')->where($where)->order('sort desc,id desc')->field('title,id,main_img,ps_time')->page(2,8)->select();
            $type = 1;
            if(!$data_next){
                $type = 2;
            }
            $this->assign('type',$type);
            $this->assign('data',$data);
            //场馆基地(顶部导航推荐)
            $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
            $this->assign('data_cg',$data_cg);
            $this->assign('data_seo',getColumnseo(3));
            return $this->fetch();
        }

        //客照内容
        public function fg(){
            $id = intval(input('param.id'));
            if($id){
                $data = Db::name('zp')->where('id',$id)->find();
                if($data['works_photo'] !==''){
                    $imgurl = Db::name('works_pic')->where('pic_id','in',$data['works_photo'])->select();
                    $data['imgurl']=$imgurl;
                }
                $this->assign('data',$data);
                //上一组
                $upId = Db::name('zp')->where('id','<',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id desc')->limit(1)->value('id');
                $this->assign('upId',$upId);
                //下一组
                $downId = Db::name('zp')->where('id','>',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id asc')->limit(1)->value('id');
                $this->assign('downId',$downId);
            }
            //活动推荐
            $hd = Db::name('activity')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->limit(2)->field('id,main_img')->select();
            $this->assign('hd',$hd);
            //场馆基地(顶部导航推荐)
            $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
            $this->assign('data_cg',$data_cg);
            $this->assign('data_seo',getColumnseo(3));
             return $this->fetch();
        }

    public  function  getmore()
    {
        $cg_id = intval(input('post.cg_id'));
        $venue_id = intval(input('post.venue_id'));
        $style_id = intval(input('post.style_id'));
        $where = 'is_del=0 and is_show=1 and sign="pc"';
        $page = intval(input('post.page'));
        //广告
        if($cg_id){
            $where .=' and cg_id = '.$cg_id;
        }
        if($style_id){
            $where .=' and style_id = '.$style_id;
        }
        if($venue_id){
            $where .=' and venue_id = '.$venue_id;
        }

        $data = Db::name('zp')->where($where)->field("id,title,main_img,ps_time")->page($page,8)->select();
        $next_data = Db::name('zp')->where($where)->order('sort desc,id desc')->field('title,id,main_img,ps_time')->page($page+1,8)->select();
        $type = 1;
        if(!$next_data){
            $type = 2;
        }
        if ($data) {
            return json(['code' => 1, 'data' => $data,'type'=>$type]);
        } else {
            return json(['code' => 0, 'msg' => '没有更多了']);
        }
    }


}